import React, {Component} from 'react';
import './index.css';
import {Input, Modal} from 'antd';

class AlertLink extends Component {

    static defaultProps = {
        visible: false,
        title: '',
        placeholder: '',
        onOk: () => {
        },
        onCancel: () => {
        }
    };

    componentWillReceiveProps(nextProps) {
        var {visible} = nextProps;
        if (visible != this.state.visible) {
            this.setState({
                visible: visible
            });
        }
    }

    constructor(props) {
        super(props);

        this.state = {
            visible: false,
            title: props.title,
        };

        this._ok = this._ok.bind(this);
        this._cancel = this._cancel.bind(this);

    }

    render() {
        var _self = this;

        return (
            <Modal
                visible={this.state.visible}
                title={this.props.title}
                onOk={this._ok}
                onCancel={this._cancel}
            >
                <Input
                    onInput={(evt) => {
                        this._val = evt.target.value;
                    }}
                    size="large"
                    placeholder={this.props.placeholder}
                />
            </Modal>
        );
    }

    _ok(evt) {
        this.props.onOk && this.props.onOk(this._val);
    }

    _cancel() {
        this.props.onCancel && this.props.onCancel();
    }

}

export default AlertLink;
